package Logic;

import java.io.IOException;
import java.sql.SQLException;

import ocsf.server.AbstractServer;
import ocsf.server.ConnectionToClient;


/**
 * This class responsible for setting the server connection
 * @author Evgeny
 * @author Igor
 * @author Samir
 * @author Konstantin
 *
 */
public class ServerHandle extends AbstractServer {
	final public static int DEFAULT_PORT = 5555;
	
	
	public ServerHandle(int port)
	{
		super(port);
	}
	
	  public static void main(String[] args) 
	  {
	    int port = 0; //Port to listen on

	    try
	    {
	      port = Integer.parseInt(args[0]); //Get port from command line
	    }
	    catch(Throwable t)
	    {
	      port = DEFAULT_PORT; //Set port to 5555
	    }
		
	    ServerHandle sv = new ServerHandle(port);
	    
	    try 
	    {
	      sv.listen(); //Start listening for connections
	    } 
	    catch (Exception ex) 
	    {
	      System.out.println("ERROR - Could not listen for clients!");
	    }
	  }
	  
	  public void serverStarted()
	  {
	    System.out.println
	      ("Server listening for connections on port " + getPort());
	  }
	  
	@Override
	protected void handleMessageFromClient(Object msg, ConnectionToClient client) throws IllegalArgumentException, IllegalAccessException, SQLException {
	
		try {
			TaskAssignment ta = new TaskAssignment(msg,client);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
